let app = getApp();
	let that = null;
	export default {
		data() {
			return {
				isIOS: app.globalData.isIOS,
				borderWidth: 1,
				listData: [],
				isLoad: false,
				id: 0,
				title: '',
				lockIcon: '/static/img/ic_lock.png',
				openIcon: '/static/img/ic_group_open.png',
				closeIcon: '/static/img/ic_group_close.png',
				appIsAudit: false,
				course: {
					is_open: false,
					code: '',
					name: '',
					section: []
				}
			};
		},
		onLoad(options) {
			(that = this).setData({
				borderWidth: that.isIOS ? 2 : 1,
				id: options.id,
				title: options.title,
				appIsAudit: app.globalData.checkAppIsAudit()
			});
			that.getChapter();
		},
		methods: {
			getChapter() {
				app.globalData.server
					.getRequest('user/chapter_question', {
						course_id: that.id
					})
					.then(function(res) {
						that.setData({
							listData: res.data,
							isLoad: true
						});
					})
					.catch(function(t) {
						app.showToast('获取章节列表失败');
					});
			},

			openTap(options) {
				let index = options.currentTarget.dataset.index;

				if (!that.listData.hasOwnProperty(index)) {
					return;
				}

				let item = that.listData[index];
				if (item.is_open) {
					item.is_open = 0;
				} else {
					item.is_open = 1;
				}

				let listData = that.listData;
				that.setData({
					listData: listData
				});
			},

			courseTap(options) {
				let item = options.currentTarget.dataset.course;
				let url =
					'../practice?title=' +
					item.name +
					'&id=' +
					that.id +
					'&extend_id=' +
					item.id +
					'&mainType=5' +
					'&max_page=' +
					item.max_page +
					'&question_type=0' +
					'&chargeType=2';
				uni.navigateTo({
					url: url
				});
			},
			onBuyTap() {
				let url = '/pages/practice/course/buy?id=' + that.id;
				uni.navigateTo({
					url: url
				});
			},
			onCourseTap() {
				let url = '/pages/practice/course/detail?id=';
				uni.navigateTo({
					url: url + that.id
				});
			}
		}
	};
